package com.missfresh.cooperation2meituan;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.ArrayList;
import java.util.ArrayList;
import java.util.ArrayList;
import java.util.List;
import java.util.List;
import java.util.List;
import java.util.List;
import java.util.Map;

import com.missfresh.cooperation2meituan.util.HttpRaw;
import com.missfresh.cooperation2meituan.util.HttpUtil;
import com.missfresh.cooperation2meituan.util.JsonUtil;
import com.missfresh.cooperation2meituan.util.SignUtil;
import com.missfresh.cooperation2meituan.vo.SysOrder;

public class Httptest {

	public static void main(String[] args) {
		try {
			/*String param = "{\"warehouse\": \"ks001\", \"t_id\": \"201509210002\",\"send_time\": \"2015-09-07 15:55:44\", "+
					" \"fromERP\": \"as\", \"shop_code\": \"ios\",\"outers\": [{\"outer_id\": \"ks001\", \"quantity\": \"11\"}, {"+
					"\"outer_id\": \"ks002\", \"quantity\": \"10\"}]}";
			//String param = readFromFile(new File("e:\\as.txt"));
			System.out.println("param"+param);
			String asresult = HttpRaw.postRaw("http://120.132.69.67:3389/atp/createOrder.json", param);
			System.out.println(asresult);
			Map<String, Object> asmap = JsonUtil.json2map(asresult);
			if("CONFLICT".equals(asmap.get("httpStatus"))){
				System.out.println(asmap.get("httpStatus"));
			}*/
			
			/*List<String> list = new ArrayList<String>();
			list.add("app_id=181");
			String timestamp = System.currentTimeMillis()+"";
			list.add("timestamp="+timestamp);
			list.add("order_id=6133845");
			String sig = SignUtil.createSign(list, "http://test.waimaiopen.meituan.com/api/v1/order/confirm");
			String mtwm_param = "app_id=181&timestamp="+timestamp+"&order_id=6133845&sig="+sig;
			String mtwm_result = "";
			mtwm_result = HttpUtil.sendGet("http://test.waimaiopen.meituan.com/api/v1/order/confirm", mtwm_param);
			Map<String, Object> resultmap = JsonUtil.json2map(mtwm_result);
			System.out.println(resultmap);*/
			
			/*List<String> list = new ArrayList<String>();
			list.add("app_id=181");
			String timestamp = System.currentTimeMillis()+"";
			list.add("timestamp="+timestamp);
			list.add("order_id=6133864");
			String reason = "orderRepeat";
			list.add("reason="+reason);
			list.add("reason_code=1301");
			String sig = SignUtil.createSign(list, "http://test.waimaiopen.meituan.com/api/v1/order/cancel");
			String mtwm_param = "app_id=181&timestamp="+timestamp+"&order_id=6133864&reason="+reason+"&reason_code=1301&sig="+sig;
			String mtwm_result = "";
			mtwm_result = HttpUtil.sendGet("http://test.waimaiopen.meituan.com/api/v1/order/cancel", mtwm_param);
			Map<String, Object> resultmap = JsonUtil.json2map(mtwm_result);
			System.out.println(resultmap);*/
			
			List<String> list = new ArrayList<String>();
			list.add("app_id=181");
			String timestamp = System.currentTimeMillis()+"";
			list.add("timestamp="+timestamp);
			list.add("app_poi_code=25381");
			String food_data = readFromFile(new File("e:\\as.txt"));
			list.add("food_data="+food_data);
			String sig = SignUtil.createSign(list, "http://test.waimaiopen.meituan.com/api/v1/food/batchinitdata");
			String mtwm_param = "app_id=181&timestamp="+timestamp+"&app_poi_code=25381&food_data="+food_data+"&sig="+sig;
			String mtwm_result = "";
			mtwm_result = HttpUtil.sendPost("http://test.waimaiopen.meituan.com/api/v1/food/batchinitdata", mtwm_param);
			Map<String, Object> resultmap = JsonUtil.json2map(mtwm_result);
			System.out.println(resultmap);
			} catch (Exception e) {
				e.printStackTrace();
			}
    }
	
	public static String readFromFile(File src) {
        try {
            BufferedReader bufferedReader = new BufferedReader(
            		new InputStreamReader(new FileInputStream(src),"GB2312"));
            StringBuilder stringBuilder = new StringBuilder();
            String content;
            while((content = bufferedReader.readLine() )!=null){
                stringBuilder.append(content);
            }
            return stringBuilder.toString();
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return null;
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return null;
        }

    }
}

